Previous lecture

Next Lecture

Syllabus

Homework

PCX Format

Header

Bitmap Data

Optional Palette

 

The first 128 bytes of every PCX file is the header, which has the

following format:

 

typedef struct _PcxHeader

{

  BYTE                  Identifier;        /* 0x00:  PCX Id Number (Always 0x0A) */

  BYTE                  Version;           /* 0x01: Version Number

0 Version 2.5 with fixed EGA palette information

2 Version 2.8 with modifiable EGA palette information

3 Version 2.8 without palette information

4 PC Paintbrush for Windows

5 Version 3.0 etc. and all 24-bit image files

For version = 5, a 768 byte palette is at the end of the file. */

  BYTE                  Encoding;          /* 0x02: Encoding Format

Always 1 for RLE */

  BYTE                  BitsPerPixel;      /* 0x03: Bits per Pixel

1, 2, 4 or 8 */

  WORD               XStart;            /* 0x04: Left of image; usually 0 */

  WORD               YStart;            /* 0x06: Top of Image; usually 0 */

  WORD               XEnd;              /* 0x08: Right of Image */

  WORD               YEnd;              /* 0x0A: Bottom of image */

  WORD               HorzRes;           /* 0x0C: Horizontal Resolution

Pixels/line or DPI; not used when decoding */

  WORD               VertRes;           /* 0x0E: Vertical Resolution

Pixels/line or DPI; not used when decoding */

  BYTE                  Palette[48];       /* 0x10: 16-Color EGA Palette */

  BYTE                  Reserved1;         /* 0x40: Reserved (Always 0) */

  BYTE                  NumBitPlanes;      /*0x41: Number of Bit Planes: 1, 3 or 4

 

Color Planes

Bits per Pixel per Plane

Max colors

Video Mode

Video date

1

1

2

Monochrome

1981

1

2

4

CGA

1981

3

1

8

EGA

1984

4

1

16

EGA and VGA

 

1

8

256

Extended VGA

1987

3

8

16,777,216

Extended VGA and XGA 

 

*/

  WORD               BytesPerLine;      /* 0x42: Bytes per Scan-line */

  WORD               PaletteType;       /* 0x44: Palette Type; usually ignored

1: color

2: gray-scale  */

  WORD               HorzScreenSize;    /*0x46: Horizontal Screen Size

Only for version 4.0 and greater. */

  WORD               VertScreenSize;    /* 0x48: Vertical Screen Size

Only for version 4.0 and greater. */

  BYTE                            Reserved2[54];     /* 0x4A: Reserved (Always 0) */

} PCXHEAD;


[Look at MS.PCX]

Identifier: 0x0A for PCX

Version: 5 for Version 3.0

Encoding:  1 for RLE

BitsPerPixel: 8

Xstart:  1

Ystart: 1

Xend: 0x20 = 32

Yend: 0x20 = 32

HorzRes: 0x60 = 96

VertRes: 0x61 = 97

EGA Palette is all 0.

NumBitPlanes = 1  ; with 8 bits/pixel gives 256 color Extended VGA

BytesPerLine = 0x20 = 32

 

Image always starts at 0x80.

PCX RLE format is described on page 671 of Murray & vanRyper.

Note that there is a typo on the lower half of page 664.  The identifier is 0Ah, not 10h.

First word is 0xCa 0x0e.  The upper two bits (C0) are set to show a run.  CA means a run of 10 pixels; value is 0e

The next bytes, 00 and 01 are uncompressed.

Next is D4 0E (run of 20 with value 0e, which takes us to the end of the first line (32 pixels).

The second line is CA 0E C3 00 01 D2 0E.  This is 10 white, 3 black, 1 gray, 18 white.

The third line (starting at 0x8D) is C9 0E 01 00 10 D0 0E for 9 white, 1 gray, 1 black, 1 red, 16 white.

 

Other colors present in the image have index values 0x14, 0x10, 0x11 and 0x04.

 

The last 0x300 bytes are the palette, in groups of 3 bytes.  The last byte in the file is at 0x54e.  Thus the palette, if present, starts at 0x24f.  If the palette is present, the byte before it (0x24e in this case) should have the value 0x0C.

 

We can find the palette entries for the colors used:

Index

Address

Red

Green

Blue

Color

0

24f

00

00

00

Black

1

252

80

80

80

Gray

4

25b

00

80

00

Dark green

E

279

ff

ff

ff

white

10

27f

ff

00

00

Red

11

282

ff

ff

00

Yellow

14

28b

00

00

ff

Blue